﻿using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shared.Swashbuckle
{
    public class SwaggerSchemaFilter : IOperationFilter
    {
        public void Apply(OpenApiOperation operation, OperationFilterContext context)
        {
            // 为操作设置默认的授权范围
            operation.Security = new List<OpenApiSecurityRequirement>
                {
                    {
                        new OpenApiSecurityRequirement
                        {
                            {
                                new OpenApiSecurityScheme
                                {
                                    Reference = new OpenApiReference
                                    {
                                        Type = ReferenceType.SecurityScheme,
                                        Id = "oauth2",
                                         
                                    }
                                },
                                new[] { "api1" } // 默认授权范围
                            }
                        }
                    }
                };

        }
    }
}
